package idv.cjcat.pyronova.nodes {
	import flash.display.BitmapData;
	import flash.geom.Matrix;
	import flash.geom.Rectangle;
	import idv.cjcat.pyronova.render.RenderVisitor;
	
	public class CopyPixels extends Node {
		
		public var source:BitmapData;
		public var sourceRect:Rectangle;
		public var mergeAlpha:Boolean;
		
		public function CopyPixels(source:BitmapData = null, sourceRect:Rectangle = null, mergeAlpha:Boolean = true) {
			this.source = source;
			this.sourceRect = sourceRect;
			this.mergeAlpha = mergeAlpha;
		}
		
		private var _matrix:Matrix = new Matrix();
		private var _pMatrix:Matrix = new Matrix();
		override public function render(visitor:RenderVisitor):void {
			if (source) {
				_matrix.identity();
				_pMatrix.tx = position.x;
				_pMatrix.ty = position.y;
				_matrix.concat(_pMatrix);
				_matrix.concat(visitor.topMatrix());
				
				visitor.graphics().copyPixels(source, sourceRect, int(_matrix.tx - center.x + 0.5), int(_matrix.ty - center.y + 0.5), mergeAlpha);
			}
		}
	}
}